﻿using System;
using System.Text;
using RAP.Framework.Libary.ServerCacheManager;
using RAP.Framework.Libary.Utils;
using RAP.Framework.Libary.DomTemplateBuilder.Interface;

namespace RAP.Framework.Libary.DomTemplateBuilder.Handler.Cache
{
	/// <summary>
	/// 清除指定键的缓存
	/// </summary>
	public class ClearCacheHandler : HandlerBase
	{
		public override void DoRender ( StringBuilder writer, object rootParamObject, object parentParamObject, ITemplateRenderContext context )
		{
			var sb = new StringBuilder ( );
			base.DoRender ( sb, rootParamObject, parentParamObject, context );
			var cacheKeys = sb.ToString ( ).Trim ( ).Split ( ',' );
			foreach ( var key in cacheKeys )
			{
				if ( key.IsNullOrEmpty ( ) )
				{
					throw new NullReferenceException ( "缓存的key不能为空！" );
				}
				CacheManager.Instance.Clear ( key.Trim ( ) );
			}
		}
	}
}
